package top.kaoshanji.p2ch19a;

/**
 * 代码清单-p2ch19a-538页a：使用ThreadLocal保存上下文信息
 * author kaoshanji
 * ^_^
 * create time 2025/2/28 15:15
 */
public class RequestContext {

    public static class Request {}

    private static ThreadLocal<String> localUserId = new ThreadLocal<>();
    private static ThreadLocal<Request> localRequest = new ThreadLocal<>();

    public static String getCurrentUserId() {
        return localUserId.get();
    }

    public static void setCurrentUserId(String userId) {
        localUserId.set(userId);
    }


    public static Request getCurrentRequest() {
        return localRequest.get();
    }

    public static void setCurrentRequest(Request request) {
        localRequest.set(request);
    }


}
